package com.jeecg.p3.system.order.web;

import com.jeecg.p3.base.util.ComCode;
import com.jeecg.p3.base.util.DateUtil;
import com.jeecg.p3.base.util.RandomUtil;
import com.jeecg.p3.system.advisor.entity.StudyAdviser;
import com.jeecg.p3.system.advisor.service.StudyAdvService;
import com.jeecg.p3.system.base.BaseController;
import com.jeecg.p3.system.order.dao.CourseOrderDao;
import com.jeecg.p3.system.order.entity.CourseOrder;
import com.jeecg.p3.system.order.entity.ProductDetails;
import com.jeecg.p3.system.order.service.CourseOrderService;
import com.jeecg.p3.system.order.service.ProductDetailsService;
import com.jeecg.p3.system.vo.LoginUser;
import org.apache.velocity.VelocityContext;
import org.jeecgframework.p3.core.common.utils.AjaxJson;
import org.jeecgframework.p3.core.util.SystemTools;
import org.jeecgframework.p3.core.util.plugin.ViewVelocity;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 订单详情处理类
 */
@Controller
@RequestMapping("/system/order/orderDetails/all")
public class ProductDetailsController extends BaseController {

    @Autowired
    private ProductDetailsService productDetailsService;
    @Autowired
    private StudyAdvService studyAdvService;

    @RequestMapping(value="/list.do",method = {RequestMethod.GET,RequestMethod.POST})
    public void toIndividual(@ModelAttribute ProductDetails query, HttpServletRequest request, HttpServletResponse response,
                             @RequestParam(required = false, value = "pageNo", defaultValue = "1") int pageNo,
                             @RequestParam(required = false, value = "pageSize", defaultValue = "10") int pageSize) throws Exception{
        PageQuery<ProductDetails> pageQuery = new PageQuery<ProductDetails>();
        pageQuery.setPageNo(pageNo);
        pageQuery.setPageSize(pageSize);
        VelocityContext velocityContext = new VelocityContext();
        pageQuery.setQuery(query);
        velocityContext.put("CourseOrder",query);
        velocityContext.put("pageInfos", SystemTools.convertPaginatedList(productDetailsService.queryPageList(pageQuery)));
        String viewName = "system/back/order/deal_order.vm";
        ViewVelocity.view(request,response,viewName,velocityContext);
    }

    /**
     *
     * @param openId 个人唯一id1
     * @return
     */
    @RequestMapping(value = "/findByopenId",method ={RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public AjaxJson findByopenId(String openId ,String productId){
        AjaxJson j = new AjaxJson();
        ProductDetails param = new ProductDetails();
        if(!openId.isEmpty()){
            param.setOpenId(openId);
            param.setProductId(productId);
            param.setUserStatus(1);
            List<ProductDetails> list = productDetailsService.findByParam(param);
            Map<String, Object> map = new HashMap<>();
            map.put("list", list);
           j.setObj(map);
           j.setSuccess(true);
           j.setMsg("查询成功");
        }else {
            j.setSuccess(false);
            j.setMsg("查询失败，openId为空");
        }
        return j;
    }





}
